home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 1 Issue 2 / PDCD-1 - Issue 02.iso / _utilities / utilities / 003 / _gs / !GS / c / IINIT < prev    next >
Text File  |  1991-10-26  |  6KB  |  208 lines

  1. /* Copyright (C) 1989, 1990, 1991 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* iinit.c */
  21. /* Initialize internally known objects for Ghostscript interpreter */
  22. #include "ghost.h"
  23. #include "alloc.h"
  24. #include "dict.h"
  25. #define INCLUDE_ERROR_NAMES        /* see errors.h */
  26. #include "errors.h"
  27. #include "name.h"
  28. #include "oper.h"
  29. #include "save.h"            /* for alloc_refs */
  30. #include "store.h"
  31.  
  32. /* Implementation parameters */
  33. #define systemdict_size 401        /* a nice prime number */
  34. #define op_array_table_size 100        /* arbitrary */
  35.  
  36. /* Standard dictionaries */
  37. ref name_errordict;
  38. /* Error names */
  39. ref name_ErrorNames;
  40.  
  41. /* The operator tables */
  42. op_def_ptr *op_def_table;
  43. uint op_def_count;
  44. ref op_array_table;    /* t_array, definitions of `operator' procedures */
  45. ushort *op_array_nx_table;        /* name indices for same */
  46. uint op_array_count;
  47.  
  48. /* Enter a name and value into systemdict */
  49. void
  50. initial_enter_name(char *nstr, ref *pref)
  51. {    ref nref;
  52.     name_enter(nstr, &nref);
  53.     if ( dict_put(&systemdict, &nref, pref) )
  54.         lprintf("dict_put failed!\n"),
  55.         gs_exit(1);
  56. }
  57.  
  58. /* Initialize objects other than operators */
  59. void
  60. obj_init()
  61. {
  62.     /* Initialize the standard objects */
  63.     ref vmark, vnull;
  64.     make_tv(&vmark, t_mark, intval, 0);
  65.     make_tv(&vnull, t_null, intval, 0);
  66.  
  67.     /* Create the system dictionary */
  68.     dict_create(systemdict_size, &systemdict);
  69.     dstack[1] = dstack[0];        /* just during initialization */
  70.  
  71.     /* Initialize the predefined names other than operators */
  72.     initial_enter_name("mark", &vmark);
  73.     initial_enter_name("null", &vnull);
  74.  
  75.     /* Create other system-known names */
  76.     name_enter("errordict", &name_errordict);
  77.     name_enter("ErrorNames", &name_ErrorNames);
  78.  
  79.     /* Create the error name table */
  80.        {    int n = sizeof(gs_error_names) / sizeof(char _ds *) - 1;
  81.         int i;
  82.         ref era;
  83.         make_tasv(&era, t_array, a_read + a_execute, n, refs,
  84.               alloc_refs(n, "obj_init(ErrorNames)"));
  85.         for ( i = 0; i < n; i++ )
  86.           name_enter((char *)gs_error_names[i], era.value.refs + i);
  87.         dict_put(&systemdict, &name_ErrorNames, &era);
  88.        }
  89. }
  90.  
  91. /* Initialize the operators */
  92.     /* Non-graphics operators */
  93. extern op_def
  94.   zarith_op_defs[], zarray_op_defs[], zcontrol_op_defs[],
  95.   zdict_op_defs[], zfile_op_defs[], zfileio_op_defs[], zgeneric_op_defs[],
  96.   zmath_op_defs[], zmisc_op_defs[], zpacked_op_defs[],
  97.   zrelbit_op_defs[], zstack_op_defs[], zstring_op_defs[],
  98.   ztype_op_defs[], zvmem_op_defs[]
  99. #ifdef LEVEL2
  100.   ,
  101.     /* Level 2 */
  102.   z2filter_op_defs[]
  103. #endif
  104.   ;
  105.     /* Graphics operators */
  106. extern op_def
  107.   zchar_op_defs[], zcolor_op_defs[], zdevice_op_defs[],
  108.   zfont_op_defs[], zfont0_op_defs[], zfont2_op_defs[],
  109.   zgstate_op_defs[], zht_op_defs[],
  110.   zmatrix_op_defs[], zpaint_op_defs[], zpath_op_defs[],
  111.   zpath2_op_defs[]
  112. #ifdef LEVEL2
  113.   ,
  114.     /* Level 2 */
  115.   z2path_op_defs[]
  116. #endif
  117.   ;
  118. private op_def_ptr op_defs_all[] = {
  119.     /* Non-graphics operators */
  120.   zarith_op_defs, zarray_op_defs, zcontrol_op_defs,
  121.   zdict_op_defs, zfile_op_defs, zfileio_op_defs, zgeneric_op_defs,
  122.   zmath_op_defs, zmisc_op_defs, zpacked_op_defs,
  123.   zrelbit_op_defs, zstack_op_defs, zstring_op_defs,
  124.   ztype_op_defs, zvmem_op_defs,
  125. #ifdef LEVEL2
  126.     /* Level 2 */
  127.   z2filter_op_defs,
  128. #endif
  129.     /* Graphics operators */
  130.   zchar_op_defs, zcolor_op_defs, zdevice_op_defs,
  131.   zfont_op_defs, zfont0_op_defs, zfont2_op_defs,
  132.   zgstate_op_defs, zht_op_defs,
  133.   zmatrix_op_defs, zpaint_op_defs, zpath_op_defs,
  134.   zpath2_op_defs,
  135. #ifdef LEVEL2
  136.     /* Level 2 */
  137.   z2path_op_defs,
  138. #endif
  139.     /* end marker */
  140.   (op_def_ptr)0
  141. };
  142.  
  143. /* Run the initialization procedures of the individual operator files. */
  144. void
  145. zop_init()
  146. {    op_def_ptr _ds *tptr;
  147.     op_def_ptr def;
  148.     for ( tptr = op_defs_all; *tptr != 0; tptr++ )
  149.        {    for ( def = *tptr; def->oname != 0; def++ ) ;
  150.         if ( def->proc != 0 )
  151.             ((void (*)(P0()))(def->proc))();
  152.        }
  153. }
  154. /* Initialize the operator table. */
  155. void
  156. op_init()
  157. {    int count = 1;
  158.     op_def_ptr _ds *tptr;
  159.     op_def_ptr def;
  160.     char _ds *nstr;
  161.  
  162.     /* Do a first pass just to count the operators. */
  163.  
  164.     for ( tptr = op_defs_all; *tptr != 0; tptr ++ )
  165.      for ( def = *tptr; def->oname != 0; count++, def++ )
  166.       ;
  167.  
  168.     /* Do a second pass to construct the operator table, */
  169.     /* and enter the operators in systemdict. */
  170.  
  171.     op_def_table = (op_def_ptr *)alloc(count, sizeof(op_def_ptr),
  172.                        "op_init(op_def_table)");
  173.     op_def_count = count;
  174.     count = 1;
  175.     for ( tptr = op_defs_all; *tptr != 0; tptr ++ )
  176.      for ( def = *tptr; (nstr = def->oname) != 0; count++, def++ )
  177.        {    /* Enter an operator into systemdict. */
  178.         /* The first character of the name is a digit */
  179.         /* giving the minimum acceptable number of operands. */
  180.         /* For now, we just skip over it. */
  181.         ref oper;
  182.         make_oper(&oper, count, (dummy_op_proc_p)(def->proc));
  183.         interp_fix_op(&oper);        /* optimize if possible */
  184.         initial_enter_name(nstr + 1, &oper);
  185.         op_def_table[count] = def;
  186.        }
  187.  
  188.     /* Allocate the table for `operator' procedures. */
  189.        {    ref *tbody =
  190.           alloc_refs(op_array_table_size, "op_array table");
  191.         make_tasv(&op_array_table, t_array, a_read+a_execute,
  192.               op_array_table_size, refs, tbody);
  193.         refset_null(tbody, op_array_table_size);
  194.         op_array_nx_table =
  195.           (ushort *)alloc(op_array_table_size, sizeof(ushort),
  196.                   "op_array nx table");
  197.         op_array_count = 0;
  198.        }
  199.  
  200. }
  201.  
  202. /* Initialize variables that hold name constants. */
  203. void
  204. init_names(register names_def _ds *pnd)
  205. {    for ( ; pnd->vname != 0; pnd++ )
  206.         name_enter(pnd->vname, pnd->pvref);
  207. }
  208.